package E2018;
import javax.swing.filechooser.FileFilter;
import java.io.File;
class JavaFilter extends FileFilter{

    @Override
    public boolean accept(File f) {
      if (f.getName().endsWith(".java")){
          return true;
      }else {
          return false;
      }
    }
    @Override
    public String getDescription() {
        return null;
    }
}
public class Exam2 {
    public static void main(String[] args) {
        JavaFilter  javaFilter = new JavaFilter();
        File file = new File("G:\\Projects\\IdeaProjects\\JavaExam\\src\\E2018\\");

        File[] listFile = file.listFiles();
        // 循环遍历数组
        for (File files : listFile) {
            boolean flag = javaFilter.accept(files);
            if(files.isDirectory()) {
                continue;
            }else{
                if (flag){
                    System.out.println(files.getName());
                }
            }
        }
    }
}
